AEL COMPUTER SCIENCE ENCYCLOPEDIA
Notes (Week 1 C) · Sovereign Documentation
⚑ 100% SILICON & COGNITIVE DEPTH
AYMAN ELMASRY
Computational Creative Director · AI Prompt Engineer
Founder of Ayman Elmasry LLC
πŸ”’ ⚑ AEL Sovereign Seal (Active Verification)
{
  "ael_seal": "AEL CS Encyclopedia β€” Β© Ayman Elmasry",
  "owner": "Ayman Elmasry",
  "legal_entities": [
    "Ayman Elmasry LLC (UAE)",
    "Ayman Elmasry Advertising & Marketing (Egypt)"
  ],
  "section": "02_Computer_Science_Notes (Week 1 C)",
  "syllabus_source": "Harvard CS50x (Deep Internal Analysis)",
  "methodology": "8-Stage Sub-Silicon Execution Paradigm",
  "system_version": "v3.0"
}

πŸ›οΈ Anatomy of C & src1 Inspection

C is a procedural, general-purpose language that affords direct memory access and low-level architectural control. In this pillar, we delve into the rigorous academic foundations of computer science, referencing the invaluable code archive src1 and lecture1.pdf.

===================================================================================
                       THE ANATOMY OF A C PROGRAM (hello2.c)
===================================================================================

  #include <cs50.h>    ──> Preprocessor Directive (CS50 Library)
  #include <stdio.h>   ──> Preprocessor Directive (Standard Input/Output)

  int main(void)       ──> Main Entry Point (Returns int 0 on success, takes void)
  {
      string answer = get_string("What's your name? "); ──> Variable Instantiation
      printf("hello, %s\n", answer);                    ──> Formatted Output (%s)
  }

===================================================================================

πŸ“¦ Data Types & Format Specifiers

C is a statically typed language. Every variable must be declared with an explicit data type, defining both its exact memory footprint in bytes and the semantic interpretation of its underlying binary sequences.

1. Primitive Data Types


πŸ”€ Control Flow & Logical Evaluation

Control flow constructs empower programs to make dynamic runtime decisions based on evaluating boolean conditions. Here we examine paradigms extracted from compare and agree codebases.

1. Conditional Branching (compare0.c)

if (x < y)
{
    printf("x is less than y\n");
}
else if (x > y)
{
    printf("x is greater than y\n");
}
else
{
    printf("x is equal to y\n");
}

2. Boolean Logical Operators (agree2.c)


πŸ”„ Iteration Constructs & Modular Design

Repetition is the bedrock of computational efficiency. Rather than duplicating logic, we leverage loop constructs and function abstraction, as demonstrated in cat and mario.

1. Iteration Paradigms (cat15.c & mario5.c)

// Input Validation using do-while (mario5.c)
int n;
do
{
    n = get_int("Size: ");
}
while (n < 1);

πŸ’‘ Modular Design & Function Prototypes

In cat15.c, Malan elucidates a foundational rule of C compilers: source files are parsed sequentially from top to bottom. Calling a custom function like meow(3) before it is explicitly declared results in a fatal compiler error.

Architectural Solution: Declaring the function signature at the top of the file (void meow(int n);), while housing the actual implementation logic below the main entry point.

#include <stdio.h>

void meow(int n); // Prototype Declaration

int main(void)
{
    meow(3);
}

void meow(int n) // Internal Implementation
{
    for (int i = 0; i < n; i++)
    {
        printf("meow\n");
    }
}